package com.ruoyi.web.controller.mySystem;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mysystem.domain.TClass;
import com.ruoyi.mysystem.service.ITClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程管理Controller
 * 
 * @author ruoyi
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/mysystem/class")
public class TClassController extends BaseController
{
    @Autowired
    private ITClassService tClassService;

    /**
     * 查询课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(TClass tClass)
    {
        startPage();
        List<TClass> list = tClassService.selectTClassList(tClass);
        return getDataTable(list);
    }

    /**
     * 导出课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:export')")
    @Log(title = "课程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TClass tClass)
    {
        List<TClass> list = tClassService.selectTClassList(tClass);
        ExcelUtil<TClass> util = new ExcelUtil<TClass>(TClass.class);
        util.exportExcel(response, list, "课程管理数据");
    }

    /**
     * 获取课程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:query')")
    @GetMapping(value = "/{cid}")
    public AjaxResult getInfo(@PathVariable("cid") Long cid)
    {
        return success(tClassService.selectTClassByCid(cid));
    }

    /**
     * 新增课程管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:add')")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TClass tClass)
    {
        return toAjax(tClassService.insertTClass(tClass));
    }

    /**
     * 修改课程管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:edit')")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TClass tClass)
    {
        return toAjax(tClassService.updateTClass(tClass));
    }

    /**
     * 删除课程管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:class:remove')")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cids}")
    public AjaxResult remove(@PathVariable Long[] cids)
    {
        return toAjax(tClassService.deleteTClassByCids(cids));
    }

    @PreAuthorize("@ss.hasPermi('mysystem:class:check')")
    @GetMapping("/check/{cids}")
    public AjaxResult check(@PathVariable Long[] cids){
        return toAjax(tClassService.checkTClassByCids(cids));
    }

    @PreAuthorize("@ss.hasPermi('mysystem:check:list')")
    @GetMapping("/checklist")
    public TableDataInfo checklist(TClass tClass){
        startPage();
        List<TClass> list = tClassService.selectCheckList(tClass);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('mysystem:check:remove')")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/checkdel/{cids}")
    public AjaxResult checkdel(@PathVariable Long[] cids)
    {
        return toAjax(tClassService.deleteCheckByCids(cids));
    }
}
